package JAVACORE_TRAINING.ADVANCED.SWING;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ButtonTutorial extends JFrame implements ActionListener {
	JLabel jLabel;
	JButton jButton;
	JButton jButton1;

	public ButtonTutorial() {
		this.setTitle("Button tutorial");
		this.setSize(400, 600);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		jLabel = new JLabel("Label Tutorial");
		add(jLabel);
		// jLabel.setText("Label Demo");
		// jLabel.setSize(50, 30);
		// jLabel.setToolTipText("This is tooltip");
		// jLabel.setForeground(Color.BLUE);

		jButton = new JButton("Redo");
		jButton.addActionListener(this);
		add(jButton, "South", 1);
		jButton1 = new JButton("Undo");
		jButton1.addActionListener(this);
		add(jButton1, "North", 1);

/*		jButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				changeText();
			}
		});*/

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		JButton btn = (JButton) e.getSource(); 
		if(btn == jButton1){
			jLabel.setText("Label Tutorial");
		}
		if (btn== jButton){
			jLabel.setText("This is updated text!");
		}

	}

	/*public void changeText() {
		jLabel.setText("This is updated label!");
	}*/

	public static void main(String[] args) {
		ButtonTutorial buttonTutorial = new ButtonTutorial();
		buttonTutorial.setVisible(true);
	}

}
